//------------------------------------------------------------------------------
//  StringUtil.cpp
//  (C) 2009 xoyojank
//------------------------------------------------------------------------------
#include "StdEddy.h"
#include "StringUtil.h"

//------------------------------------------------------------------------------
namespace Eddy
{

//------------------------------------------------------------------------------
String&
StringUtil::ToMultiByte(String& dest, const WString& src)
{
    int const length = WideCharToMultiByte(CP_ACP, 0, src.c_str(), int(src.size()), NULL, 0, NULL, NULL);
    std::vector<char> tmp(length + 1);
    WideCharToMultiByte(CP_ACP, 0, src.c_str(), int(src.size()), &tmp[0], length, NULL, NULL);
    dest.assign(tmp.begin(), tmp.end() - 1);

    return dest;
}

//------------------------------------------------------------------------------
WString&
StringUtil::ToUnicode(WString& dest, const String& src)
{
    int const length = MultiByteToWideChar(CP_ACP, 0, src.c_str(), int(src.size()), NULL, 0);
    std::vector<wchar_t> tmp(length + 1);
    MultiByteToWideChar(CP_ACP, 0, src.c_str(), int(src.size()), &tmp[0], length);
    dest.assign(tmp.begin(), tmp.end() - 1);

    return dest;
}

}// Eddy
